////////////////////////////////////////////////////////////////////////////////////////////////////
// Name    : Ronny Remesnik
// ID      : 310323878
// Date    : 24-11-2009
// Time    : 21:47 PM
// Lecturer: Miss Keren Kalif
//
// Spacial Notes For The Lecturer:
// -------------------------------
// In this project used special library "screen" created also by me last year, that
// envolves the user interaction with the software, and alows special functions like
// input, menus, color and screen stuff.
// This unit called screen.h & screen.cpp is not yet object oriented and it uses static methods.
//
////////////////////////////////////////////////////////////////////////////////////////////////////
#include <iostream>
#include "CDate.h"
#include "CDevice.h"
#include "CGymClub.h"
#include "CExercise.h"
#include "screen.h"
#include <conio.h>

using namespace std;
char *GymMenu[6]={
							"Add New Trainer",
							"Add New Device",
							"Add Exercise To Trainer",
							"Print All Devices",
							"Print All Trainers",
							"Print Program Of Trainer"
							};


void main()
{	
	int action;
	CDate todayDate; 

	char *GymName = screen::readvalue("Please Enter Gym Name: ",TEXT_S,0,20,NULL);
	if (strlen(GymName)==0)
		exit(1);

	CGymClub Gym(GymName);
	delete []GymName;

do
{
	system("cls");
	screen::box(0,0,79,5);
	screen::gotoxy(30,22);
	cout<<"Today is: "; todayDate.Show();
	screen::box(10,21,69,23);

	screen::puttext("Welcome to The Gym Software !",30,1,0x0d);
	screen::puttext("Gym Name: ",35,3,0x0f);
	screen::gotoxy(45,3);
	cout<<"[ "<<Gym.getClubName()<<" ]";


	action = screen::menu(GymMenu,6,0,"Select Action:",10);

	if (action==0)
	{
		char *tname = screen::readvalue("Enter Trainer Name: ",TEXT_S,0,20,NULL);
		if (Gym.addTrainer(tname)==REGISTER_FAIL_CLUB_FULL)
		{
			screen::cls();
			screen::gotoxy(1,1);
			cout<<"Cannot Add Trainer Club Is Full !"<<endl;
			_getch();
		}
		delete []tname;
	}
	if (action==1)
	{
		char *tdevice = screen::readvalue("Enter Device Name: ",TEXT_S,0,20,NULL);
		Gym.addDevice(tdevice);
		delete []tdevice;
	}
	if (action==2)
	{
		screen::cls();
		if ( Gym.getDeviceCount() == 0)
		{
			cout<<"No Devices In The Gym Yet !"<<endl;
			_getch();
		}
		else if (Gym.getTrainerCount() == 0)
		{
			cout<<"No Trainers In The Gym Yet !"<<endl;
			_getch();
		}
		else
			{
				char **allTrainers;
				char **allDevices;
				int trainerSelect;

				Gym.getGymTrainers(allTrainers);
				Gym.getGymDevices(allDevices);
				trainerSelect  = screen::menu(allTrainers,Gym.getTrainerCount(),0,"Select Trainer",10);

				if (trainerSelect!=-1)
					{
						int deviceSelect;
						screen::cls();
						deviceSelect  = screen::menu(allDevices,Gym.getDeviceCount(),0,"Select Device",10);
						
						if (deviceSelect != -1)
							{
								if (Gym.getTrainerbyName(allTrainers[trainerSelect])->getProgram().addExercise(new CExercise(*Gym.getDevicebyName(allDevices[deviceSelect])),CDate()) == DEVICE_EXIST)                                     
								{
									screen::cls();
									screen::gotoxy(0,0);
									cout<<"Device Already Exist In This Program..."<<endl;
									_getch();
								}
							}
						
					
					}
				Gym.freeStrings(allTrainers,Gym.getTrainerCount());
				Gym.freeStrings(allDevices,Gym.getDeviceCount());
			}

	}
	if (action==3)
	{
		screen::cls();
		if (Gym.getDeviceCount()==0)
			cout<<"There Are No Devices Yet !"<<endl;
		else
			for(int i=0;i<Gym.getDeviceCount();i++)
				cout<<"Device: "<<i+1<<" = "<<Gym.getDevice(i)->getDeviceName()<<endl;
		_getch();
	}
	if (action==4)
	{
		screen::cls();
		if (Gym.getTrainerCount()==0)
			cout<<"There Are No Trainers Yet !"<<endl;
		else
			for(int i=0;i<Gym.getTrainerCount();i++)
				cout<<"Trainer: "<<i+1<<" = "<<Gym.getTrainer(i)->getTrainerName()<<endl;
		
		_getch();
	}
	if (action==5)
	{
		char **allTrainers;
		int trainerSelect;

		screen::cls();
		if (Gym.getTrainerCount()==0)
		{
			cout<<"There Are No Trainers Yet !"<<endl;
			_getch();
		}
		else
		{
			Gym.getGymTrainers(allTrainers);
			trainerSelect  = screen::menu(allTrainers,Gym.getTrainerCount(),0,"Select Trainer",10);

			if (trainerSelect!=-1)
				{
					screen::cls();
					screen::gotoxy(0,0);
					if (Gym.getTrainerbyName(allTrainers[trainerSelect])->getProgram().getExerciseCount()==0)
					{
						cout<<" Trainer ["<<allTrainers[trainerSelect]<<"] Have No Exercises !"<<endl;
						_getch();
					}
					else
					{
						cout<<"Program of: "<<allTrainers[trainerSelect]<<endl;
						cout<<"Last Update: ";
						Gym.getTrainerbyName(allTrainers[trainerSelect])->getProgram().getProgramDate().Show();
						for(int i=0;i<Gym.getTrainerbyName(allTrainers[trainerSelect])->getProgram().getExerciseCount();i++)
							cout<<"Exercise: "<<i+1<<" = "<< Gym.getTrainerbyName(allTrainers[trainerSelect])->getProgram().getExercise(i)->getDevicePtr()->getDeviceName()<<endl;
						_getch();
					}//end Exercises Count
				}// end trainerSelect
		Gym.freeStrings(allTrainers,Gym.getTrainerCount());
		}// end trainerCount
	}//end action 5

}
while (action!=-1);
}